﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Portal.Logic.Tests.Units;
using Portal.Model;
using Rhino.Mocks;
using FluentAssertions;

namespace Portal.Logic.Validators.Tests.Units
{
	[TestClass]
	public class UserValidatorTests : BaseTests
	{

		protected override void InitializeTest() { }

		#region Validate
		[TestMethod]
		public void Validate_UserIsValid_ResultIsValid()
		{
			var validator = GetValidator();
			var user = Mocks.Stub<IUser>();
			user.LastName = "last name";
			user.FirstName = "first name";
			SetupResult.For(user.Login).Return("login");

			Mocks.ReplayAll();

			var result = validator.Validate(user);

			result.IsValid.Should().BeTrue();
		}

		[TestMethod]
		public void Validate_UserLastNameHasMoreThan50Chars_ResultIsNotValid()
		{
			var validator = GetValidator();
			var user = Mocks.Stub<IUser>();
			user.LastName = "over 50 chars       123456789 123456789 123456789 1";
			user.FirstName = "first name";
			SetupResult.For(user.Login).Return("login");

			Mocks.ReplayAll();

			var result = validator.Validate(user);

			result.IsValid.Should().BeFalse();
			result.Errors.Count.Should().Be(1);
		}

		[TestMethod]
		public void Validate_UserFirstNameHasMoreThan50Chars_ResultIsNotValid()
		{
			var validator = GetValidator();
			var user = Mocks.Stub<IUser>();
			user.FirstName = "over 50 chars       123456789 123456789 123456789 1";
			user.LastName = "last name";
			SetupResult.For(user.Login).Return("login");

			Mocks.ReplayAll();

			var result = validator.Validate(user);

			result.IsValid.Should().BeFalse();
			result.Errors.Count.Should().Be(1);
		}

		[TestMethod]
		public void Validate_UserLoginHasMoreThan50Chars_ResultIsNotValid()
		{
			var validator = GetValidator();
			var user = Mocks.Stub<IUser>();
			user.LastName = "last name";
			user.FirstName = "first name";
			SetupResult.For(user.Login).Return("over 50 chars       123456789 123456789 123456789 1");

			Mocks.ReplayAll();

			var result = validator.Validate(user);

			result.IsValid.Should().BeFalse();
			result.Errors.Count.Should().Be(1);
		}

		[TestMethod]
		public void Validate_UserLoginIsEmpty_ResultIsNotValid()
		{
			var validator = GetValidator();
			var user = Mocks.Stub<IUser>();
			user.LastName = "last name";
			user.FirstName = "first name";

			Mocks.ReplayAll();

			var result = validator.Validate(user);

			result.IsValid.Should().BeFalse();
			result.Errors.Count.Should().Be(1);
		}

		#endregion

		private UserValidator GetValidator()
		{
			return new UserValidator();
		}
	}
}
